import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;



public class Setting {
	
	private Properties properties = null;
	private File propsFile = null;
	private FileInputStream fis = null;
	private FileOutputStream fos = null;
	private String propsPath = "DBConnection.properties";

	public Setting() {
		this.propsFile = new File( this.propsPath);
		this.properties = new Properties();
		
		try {
			if ( !this.propsFile.exists())
				this.propsFile.createNewFile();
			
			this.fis = new FileInputStream( this.propsFile);
			this.properties.load( this.fis);
//			this.properties.loadFromXML( this.fis);
//			properties.loadFromXML( new FileInputStream( this.propsPath));
		} catch ( IOException e) {
			e.printStackTrace();
		}
	}
	
	public Properties getProperties() {
		return properties;
	}
	
	public String getProperties( String key) {
		return this.properties.getProperty( key);
	}

	public void setProperties(Properties properties) {
		this.properties = properties;
	}
	
	public void setProperties( String path) {
		this.propsPath = path;
	}
	
	public void setProperties( String key, String value) {
		this.properties.setProperty( key, value);
	}
	
	public void storeProperty() throws IOException {
//		this.properties.storeToXML(this.fos, "DB Connection");
		this.fos = new FileOutputStream( this.propsFile);
		this.properties.store( this.fos, "DB Connection");
	}
	
	public static void main( String[] arg) throws IOException {
//		Setting props = new Setting();
//		props.setProperties( "user", "scott");
//		props.setProperties( "password", "tiger");
//		props.storeProperty();
//		System.out.println( "user = " + props.getProperties( "user"));
//		System.out.println( "password = " + props.getProperties( "password"));
		System.out.println( System.getProperty("user.dir") + "\\configuration\\.dbconnection.properties");
	}
}

